<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

namespace App\AdminApi\Controller;

use App\AdminApi\BasicsController;
use App\AdminApi\Modular\Administer\Service\DepartmentService;
use App\Common\Enums\SexEnums;
use App\Common\Extend\Guard\Auth;
use App\Common\Modular\Administer\Search\UserSearch;
use App\Common\Modular\Administer\Serve\JobServe;
use App\Common\Modular\Data\Serve\RegionServe;
use Core\HyperfUnit\Response;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Psr\Http\Message\ResponseInterface;
use Zms\Unit\Is;

#[
    Controller(prefix: '/admin-api/filter-panel', server: self::SERVER),
    Auth(guard: self::GUARD, sign: 'skip', app: self::APP)
]
class FilterPanelController extends BasicsController
{
    #[
        GetMapping('depauth-user'),
        Auth(label: ['部门授权数据员工'], logger: false)
    ]
    public function DepauthUser(): ResponseInterface
    {
        $where = $this->request->all();
        if (!(isset($where['id']) && Is::notEmpty($where['id']))) {
            $where['id'] = $this->dataAuth();
        }
        $search = new UserSearch([
            'where' => $where,
            'column' => ['id', 'nickname', 'avatar'],
        ]);
        return Response::Api()->success(data: $search->search());
    }

    #[
        GetMapping('job-list'),
        Auth(label: ['获取岗位信息'], logger: false)
    ]
    public function JobList(JobServe $serve): ResponseInterface
    {
        $where = $this->request->all();
        $paginate = $serve->search($where)->orderByRaw($this->orderBy())->paginate($this->pageSize());
        return Response::Api()->success(data: $paginate);
    }

    #[
        GetMapping('dep-tree'),
        Auth(label: ['部门筛选数据'], logger: false)
    ]
    public function DepTree(DepartmentService $service): ResponseInterface
    {
        return Response::Api()->success(data: [
            'list' => $service->getDepartmentData(),
        ]);
    }

    #[
        GetMapping('province-city-tree'),
        Auth(label: ['省市二级区数据'], logger: false)
    ]
    public function ProvinceCityByTree(): ResponseInterface
    {
        return Response::Api()->success(data: container(RegionServe::class)->getProvinceCityByTree());
    }


    #[
        GetMapping('sex'),
        Auth(label: ['性别数据'], logger: false)
    ]
    public function sex(): ResponseInterface
    {
        return Response::Api()->success(data: SexEnums::Datas());
    }
}
